import LogFactory from "../log/LogFactory.js";
import RequestHandler from "../util/RequestHadler.js";
import { IDENTITY_MAP } from "./constant.js";

const log = LogFactory.getLogger("Table");
export default class Table {

    tableBody = null;
    data = null;

    async init(){
        this.tableBody = $("#scoreTableData")
        // log.debug(this.tableBody);
    }

    async refreshTable(){
        this.data = await RequestHandler.get("/scoring/list");
        // log.debug("刷新table", this.data);
        this.tableBody.empty();
        this.data.map((e,i) => {
        //    log.debug(e,i);
            const tr = $(`<tr></tr>`)
            const th = $(`<th scope="row">${i+1}</th>`)
            const td0 = $(`<td>${e.id}</td>`)
            const td1 = $(`<td>${e.chang / 100}</td>`)
            const td2 = $(`<td>${e.ma / 100}</td>`)
            const td3 = $(`<td>${e.jun / 100}</td>`)
            const td4 = $(`<td>${IDENTITY_MAP.get(e.landlord)}</td>`)
            const td5 = $(`<td>${e.createTime}</td>`)
            tr.append(th,td0,td1,td2,td3,td4,td5);
            this.tableBody.append(tr);
        })
    }
}